<script setup>
import {useUserStore} from "@/store/user.js";

const userStore = useUserStore();
const user = userStore.user;

const props = defineProps({
  permission: {
    type: [String, Array],
  }
});
const {permissions} = user;
const showSlot = computed(() => {
  // 没有传入权限，直接显示
  if (!props.permission) {
    return true;
  }
  if (!permissions) {
    return false;
  }
  if (Array.isArray(props.permission)) {
    return props.permission.every(item => {
      permissions.includes(item);
    });
  } else {
    return permissions.includes(props.permission);
  }
});

</script>

<template>
  <slot v-if="showSlot" :userPermissions="permissions"></slot>
</template>

<style scoped lang="less">

</style>